// JavaScript Document 11
var smsCooldownTime = 90;
var newOrderInterval = 5000;//millisec / 1000
var Ucenter = new Object();
Ucenter.smsCooldownTime = smsCooldownTime;
Ucenter.smsCooldownBtn = '';
Ucenter.htmlEncode = function (text) {
    return text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
Ucenter.popover_placement = 'right';
//通用函数
Ucenter.trim = function (text) {
    if (typeof(text) == "string") {
        return text.replace(/^\s*|\s*$/g, "");
    }
    else {
        return text;
    }
}

Ucenter.isEmpty = function (val) {
    switch (typeof(val)) {
        case 'string':
            return Ucenter.trim(val).length == 0 ? true : false;
            break;
        case 'number':
            return val == 0;
            break;
        case 'object':
            return val == null;
            break;
        case 'array':
            return val.length == 0;
            break;
        default:
            return true;
    }
}

// 判断是否是身份证
Ucenter.IdentityCodeValid = function (code) {
    var city = {
        11: "北京",
        12: "天津",
        13: "河北",
        14: "山西",
        15: "内蒙古",
        21: "辽宁",
        22: "吉林",
        23: "黑龙江 ",
        31: "上海",
        32: "江苏",
        33: "浙江",
        34: "安徽",
        35: "福建",
        36: "江西",
        37: "山东",
        41: "河南",
        42: "湖北 ",
        43: "湖南",
        44: "广东",
        45: "广西",
        46: "海南",
        50: "重庆",
        51: "四川",
        52: "贵州",
        53: "云南",
        54: "西藏 ",
        61: "陕西",
        62: "甘肃",
        63: "青海",
        64: "宁夏",
        65: "新疆",
        71: "台湾",
        81: "香港",
        82: "澳门",
        91: "国外 "
    };
    var tip = "";
    var pass = true;


    var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
    if (reg.test(code) === false) {
        tip = "身份证号格式错误";
        pass = false;
    }
    // if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
    //     tip = "身份证号格式错误";
    //     pass = false;
    // }

    else if (!city[code.substr(0, 2)]) {
        tip = "地址编码错误";
        pass = false;
    }
    else {
        //18位身份证需要验证最后一位校验位
        if (code.length == 18) {
            code = code.split('');
            //∑(ai×Wi)(mod 11)
            //加权因子
            var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
            //校验位
            var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
            var sum = 0;
            var ai = 0;
            var wi = 0;
            for (var i = 0; i < 17; i++) {
                ai = code[i];
                wi = factor[i];
                sum += ai * wi;
            }
            var last = parity[sum % 11];
            if (parity[sum % 11] != code[17]) {
                tip = "身份证校验位错误";
                pass = false;
            }
        }
    }
    if (!pass) alert(tip);
    return pass;
}
// 绑定菜品到导航栏
Ucenter.bind_nav = function (obj, bind_type, url) {
    var menu_nav_id = $(obj).val();
    var menu_id = $(obj).find("option:selected").attr("menu_id");
    var bind_type = bind_type;
    $.ajax({
        type: "GET",
        url: url,
        data: {bind_type: bind_type, menu_nav_id: menu_nav_id, menu_id: menu_id},
        dataType: "json",
        success: function (data) {
            if (data.error == 1) {
                alert(data.message);
            }
        },
        error: function () {
            alert('网络异常');
        }
    });
}

Ucenter.isNumber = function (val) {
    var reg = /^[\d|\.|,]+$/;
    return reg.test(val);
}
Ucenter.isMobile = function (mobile) {
    var reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
    return reg.test(mobile);
}

Ucenter.isInt = function (val) {
    if (val == "") {
        return false;
    }
    var reg = /\D+/;
    return !reg.test(val);
}

Ucenter.isEmail = function (email) {
    var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
    return reg1.test(email);
}

Ucenter.isTel = function (tel) {
    var reg = /^[\d|\-|\s|\_]+$/; //只允许使用数字-空格等
    return reg.test(tel);
}


Ucenter.fixEvent = function (e) {
    var evt = (typeof e == "undefined") ? window.event : e;
    return evt;
}

Ucenter.srcElement = function (e) {
    if (typeof e == "undefined") e = window.event;
    var src = document.all ? e.srcElement : e.target;
    return src;
}

Ucenter.isTime = function (val) {
    var reg = /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/;
    return reg.test(val);
}
Ucenter.callback = function (callback, params) {
    if (typeof(callback) === "function") {
        callback.call(self, params);
    } else {
        alert(callback + ' is not a function');
    }
}
//
Ucenter.alert = function (res, callback) {
    <!-- Small modal -->
    var message = res.message != 'undefined' ? res.message : '';
    var alertMessage = res.alertMessage != undefined ? res.alertMessage : '';   //弹出框，并且跳转
    if (message.length > 0) {
        var modalId = "smallAlertModal";
        var eleStr = '<div id="' + modalId + '" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">' +
            '<div class="modal-dialog modal-sm">' +
            '<div class="modal-content">' +
            '<div class="modal-header">' +
            '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>' +
            '<h4 class="modal-title" id="myModalLabel">系统消息</h4>' +
            '</div>' +
            '<div class="modal-body">' + res.message + '</div>' +
            '<div class="modal-footer">' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">确 定</button>' +
            '</div>' +
            '</div>' +
            '</div></div>';
        $('body').append(eleStr);
        $('#' + modalId).modal('show');
        $('#' + modalId).on('hidden.bs.modal', function (e) {
            if (res.redirect) {
                //alert(res.redirect);
                document.location = res.redirect;
            }
            $('#' + modalId).remove();
            if (typeof(callback) == 'function') {
                callback();
            }
        })
    } else if (alertMessage.length > 0) {
        var modalId = "smallAlertModal";
        var eleStr = '<div id="' + modalId + '" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">' +
            '<div class="modal-dialog modal-sm">' +
            '<div class="modal-content">' +
            '<div class="modal-header">' +
            '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>' +
            '<h4 class="modal-title" id="myModalLabel">系统消息</h4>' +
            '</div>' +
            '<div class="modal-body">' + res.alertMessage + '</div>' +
            '<div class="modal-footer">' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">确 定</button>' +
            '</div>' +
            '</div>' +
            '</div></div>';
        $('body').append(eleStr);
        $('#' + modalId).modal('show');
        $('#' + modalId).on('hidden.bs.modal', function (e) {
            if (res.redirect) {
                //alert(res.redirect);
                document.location = res.redirect;
            }
            $('#' + modalId).remove();
            if (typeof(callback) == 'function') {
                callback();
            }
        })
    } else {
        if (typeof(callback) == 'function') {
            callback();
        }
    }
}
Ucenter.confirm = function (msg) {
    <!-- Small modal -->
    var modalId = "smallAlertModal";
    var eleStr = '<div id="' + modalId + '" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">' +
        '<div class="modal-dialog modal-sm">' +
        '<div class="modal-content">' +
        '<div class="modal-header">' +
        '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>' +
        '<h4 class="modal-title" id="myModalLabel">系统消息</h4>' +
        '</div>' +
        '<div class="modal-body">' + msg + '</div>' +
        '<div class="modal-footer">' +
        '<button type="button" class="btn btn-default">确 定</button>' +
        '<button type="button" class="btn btn-danger" data-dismiss="modal">确 定</button>' +
        '</div>' +
        '</div>' +
        '</div></div>';
    $('body').append(eleStr);
    $('#' + modalId).modal('show');
    $('#' + modalId).on('hidden.bs.modal', function (e) {
        $('#' + modalId).remove();
        return false;
    })
    return false;
}
Ucenter.inputSetOk = function (obj) {
    //$(obj).removeClass('error').addClass('ok');
    $(obj).parents('.form-group').removeClass('has-warning').removeClass('has-error').addClass('has-success');
    $(obj).parent().children('.form-control-feedback').removeClass('glyphicon-warning-sign').removeClass('glyphicon-remove').addClass('glyphicon-ok');
    $(obj).popover('destroy');
}
Ucenter.inputSetWarning = function (obj, msg) {
    $(obj).parents('.form-group').removeClass('has-success').removeClass('has-error').addClass('has-warning');
    $(obj).parent().children('.form-control-feedback').removeClass('glyphicon-ok').removeClass('glyphicon-remove').addClass('glyphicon-warning-sign');
    if (typeof(msg) != "undefined" & msg != '') {
        this.showPopover(obj, msg);
    }
}
Ucenter.inputSetError = function (obj, msg) {
    //$(obj).removeClass('ok').addClass('error');
    $(obj).parents('.form-group').removeClass('has-success').removeClass('has-warning').addClass('has-error');
    $(obj).parent().children('.form-control-feedback').removeClass('glyphicon-ok').removeClass('glyphicon-warning-sign').addClass('glyphicon-remove');
    if (typeof(msg) != "undefined" & msg != '') {
        this.showPopover(obj, msg);
    }
}
Ucenter.showPopover = function (obj, msg) {
    var popoverOption = {
        'content': msg, 'html': true,
        'trigger': 'manual',
        'placement': Ucenter.popover_placement
    }
//	if(typeof extOption != "undefined"){
//		$.extend(popoverOption, extOption);
//	}
    var popoverObj = $(obj), container = $(obj).attr('data-popover-place');
    var tipPlace = $(obj).attr('data-tipPlace');
    if (typeof tipPlace != "undefined") {
        popoverOption.placement = tipPlace;
    }
    if (typeof container != "undefined" & container == 'parent') {
        popoverObj = $(obj).parent();
    }
    popoverObj.popover('destroy').popover(popoverOption).popover('show');
}
Ucenter.sendSms = function (mobile) {
    var obj = "#" + this.smsCooldownBtn;
    if (!Ucenter.isMobile(mobile)) {
        var msg = '请输入正确的手机号码！';
        Ucenter.inputSetError(obj, msg);
        return false;
    } else {
        $("#" + this.smsCooldownBtn).val("发送中……").addClass('disabled');
        $.getJSON(BASE_URI + "comm/send_signup_sms/" + mobile, function (res) {
            if ('undefined' == res || res.error > 0) {
                Ucenter.inputSetError(obj, res.message);
                $(obj).val("获取验证码").removeClass('disabled');
            } else {
                Ucenter.smsCooldown();
                $(obj).popover('destroy').popover({
                    'content': '请注意查收短消息！', 'html': true,
                    'trigger': 'manual',
                    'placement': Ucenter.popover_placement
                }).popover('show');

            }
        });
    }
}
Ucenter.smsCooldown = function () {
    if (this.smsCooldownTime > 1) {
        this.smsCooldownTime--;
        $("#" + this.smsCooldownBtn).val(this.smsCooldownTime + "秒后重新获取").addClass('disabled');
        setTimeout("Ucenter.smsCooldown()", 1000);
    } else {
        $("#" + this.smsCooldownBtn).val("获取验证码").removeClass('disabled');
        $("#" + this.smsCooldownBtn).popover('destroy');
        this.smsCooldownTime = smsCooldownTime;
        clearTimeout();
    }
}


document.getCookie = function (sName) {
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
            return decodeURIComponent(aCrumb[1]);
    }

    // a cookie with the requested name does not exist
    return null;
}

document.setCookie = function (sName, sValue, sExpires) {
    var sCookie = sName + "=" + encodeURIComponent(sValue);
    if (sExpires != null) {
        sCookie += "; expires=" + sExpires;
    }

    document.cookie = sCookie;
}

document.removeCookie = function (sName, sValue) {
    document.cookie = sName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

$("#REGcaptcha").focus(function (e) {
    $(".vcodeEle").click(function (e) {
        var vcodeSrc = $("img.vcodeEle").attr('src').split('?')[0];
        $("img.vcodeEle").attr('src', vcodeSrc + "?" + Math.random());
    });
    if ($("#vcodePanel").hasClass('hide')) {
        $("img.vcodeEle").trigger('click');
    }
    $("#vcodePanel").removeClass('hide');
});
$("#REGagreement").click(function (e) {
    confirmRegStatus();
});
$("#Iagreed").click(function (e) {
    $("#agreementModal").modal('hide');
    $("#REGagreement").prop('checked', true);
});

$('[data-demand="required"]').on('blur', this, function (e) {
    checkInputValue($(this));
})
function checkInputValue(obj) {
    var value = $(obj).val(), msg = null, errType = 'error';
    switch ($(obj).attr('name')) {
        case 'realname':
            if (Ucenter.isEmpty(value)) {
                msg = '真实姓名不能为空！';
                errType = 'error';
            } else {
                data_auto_check(obj);
            }
            break;
        case 'username':
            if (Ucenter.isEmpty(value)) {
                msg = '用户名不能为空！';
                errType = 'error';
            } else {
                data_auto_check(obj);
            }
            break;
        case 'mobile':
            if (Ucenter.isEmpty(value)) {
                msg = '手机号码不能为空！';
                errType = 'error';
            } else if (!Ucenter.isMobile(value)) {
                msg = '请输入有效的手机号码！';
                errType = 'error';
            }
            break;
        case 'email':
            if (Ucenter.isEmpty(value)) {
                msg = '邮箱地址不能为空！';
                errType = 'error';
            } else if (!Ucenter.isEmail(value)) {
                msg = '请输入有效邮箱地址！';
                errType = 'error';
            } else {
                data_auto_check(obj);
            }
            break;
        case 'service_time':
            var label = $(obj).parents('.form-group').children('label').html();
            if (Ucenter.isEmpty(value)) {
                msg = label + '不能为空！';
                errType = 'error';
            } else if (value == 0) {
                if ($('input[name="service_type"]:checked').val() < 2) {
                    msg = label + '不能为0！';
                    errType = 'error';
                }
            }
            break;
        case 'new_password':
            if (Ucenter.isEmpty(value)) {
                msg = '请输入新密码！';
                errType = 'error';
            } else if (value.length < 6) {
                msg = '新密码不能小于6位！';
                errType = 'error';
            }
        case 'confirm_pwd':
            var pwd = $(obj).parents('form').find('[name="new_password"]').val();
            if (Ucenter.isEmpty(value)) {
                msg = '请再次输入新密码！';
                errType = 'error';
            } else if (value != pwd) {
                msg = '新密码输入不一致！';
                errType = 'error';
            }
            break;
        default:
            if (Ucenter.isEmpty(value)) {
                var lable = $(obj).parent().children('label').html();
                if ((typeof lable == "undefined")) {
                    lable = $(obj).parent().parent().find('label').html();
                }
                msg = lable + '不能为空！';
                errType = 'error';
            } else {
                var check_url = $(obj).attr('data-autocheck-url');
                if ((typeof check_url != "undefined") && check_url.length > 0) {
                    data_auto_check(obj);
                }
            }
            break;
    }
    confirmRegStatus();
    if (msg == null) {
        Ucenter.inputSetOk(obj);
        return true;
    } else {
        if (errType == 'error') {
            Ucenter.inputSetError(obj, msg);
        } else {
            Ucenter.inputSetWarning(obj, msg);
        }
        return false;
    }
}
function data_auto_check(obj) {
    var value = encodeURIComponent($(obj).val()), check_url = $(obj).attr('data-autocheck-url');
    if ((typeof check_url != "undefined") && check_url.length > 0) {
        if (check_url.charAt(check_url.length - 1) != '/') {
            check_url += '/';
        }//alert(BASE_URI+check_url+value);
        $.getJSON(BASE_URI + check_url + value, function (res) {
            if ('undefined' == res || res.error > 0) {
                Ucenter.inputSetError(obj, res.message);
            } else {
                Ucenter.inputSetOk(obj);
            }
            confirmRegStatus();
        });
    }
}
function autoCheckSmsCode(obj) {
    var value = $(obj).val();
    $.getJSON(BASE_URI + "comm/check_signup_sms/" + value, function (res) {
        if ('undefined' == res || res.error > 0) {
            Ucenter.inputSetError(obj, res.message);
        } else {
            Ucenter.inputSetOk(obj);
        }
    });
}
function confirmRegStatus() {
    var inputSize = $('#step1-signup-form [data-demand="required"]').size();
    var okSize = $('#step1-signup-form [data-demand="required"]').parents('.form-group.has-success').size();
    var agreement = $("#REGagreement").is(":checked");
    //$("#testMsg").html(inputSize + ' =/= ' + okSize).removeClass('sr-only');
    if (inputSize == okSize & agreement) {
        $("#REGsubmitStep1").removeClass('disabled');
    } else {
        $("#REGsubmitStep1").addClass('disabled');
    }//$("#REGsubmitStep1").removeClass('disabled');
}

/**
 * 提交登录表单
 */
$('[data-form="ajaxSubmit"]').submit(function () {
    $(this).ajaxSubmit({
        timeout: 3000,
        beforeSubmit: function (formData, jqForm, options) {
            return Ucenter.beforeSubmitResponse();
        },  //提交前的回调函数
        success: function (responseText, statusText) {
            try {
                var res = $.parseJSON(responseText);
                if ('undefined' == res || res.error > 0) {
                    Ucenter.submitResponseError(res);
                } else {
                    document.location = res.redirect;
                }
            } catch (e) {
                Ucenter.alert({message: statusText + ":数据异常……\r\n[" + responseText + "]"});
            }
            return false;
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            Ucenter.alert({message: [textStatus, errorThrown]});
        }
    })
    return false;
})

//文件上传插件
Ucenter.creatUploadify = function (objs, post_data, success_callback) {
    if (typeof($(objs).attr("data-action")) == 'undefined') return false;
    var action = $(objs).attr("data-action"),
        uploaderPath = BASE_URI + action;
    $.getScript('js/uploadify3.2/jquery.uploadify.min.js', function () {
        $(objs).each(function (index, element) {
            var buttonText = $(element).attr("data-button-text");
            var uploadMulti = $(element).attr("data-uploader_multi");
            uploadMulti = typeof(uploadMulti) == "undefined" ? false : true;
            var formData = typeof(post_data) == 'object' & post_data != null ? post_data : {};

            if (typeof($(element).attr("data-post")) != 'undefined') {
                //限定格式：注意双引号 '{"itemid":"1","sessid":"111"}';
                //JSON.parse() = $.parseJSON();JSON.stringify();
                $.extend(formData, $.parseJSON($(element).attr("data-post")));
            }
            var formData = {'action': $(objs).attr("file-action")};
            $.extend(formData, post_data);
            $(element).uploadify({
                'uploader': uploaderPath, 'formData': formData, 'debug': false,
                'swf': 'js/uploadify3.2/uploadify.swf?' + Math.random(),
                'cancelImage': 'js/uploadify3.2/uploadify-cancel.png',
                'fileObjName': 'Filedata',//服务器端脚本使用的文件对象的名称 $_FILES个['upload']
                'auto': true, 'multi': uploadMulti, 'successTimeout': 30,//是否自动上传
                'removeCompleted': true, 'removeTimeout': 1,
                'buttonText': buttonText, 'buttonImage': null, 'width': '120', 'height': '30',
                'overrideEvents': ['onDialogClose'],//不执行默认的onSelect事件
                //'queueID':'uploadfileQueue',//文件选择后的容器ID
                //在浏览窗口底部的文件类型下拉菜单中显示的文本
                'fileTypeDesc': '支持的格式：', 'fileTypeExts': '*.jpg;*.gif;*.png',
                //上传文件的大小限制//上传数量
                'fileSizeLimit': '2MB', 'queueSizeLimit': 25,
                'onUploadProgress': function (file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
                    //有时候上传进度什么想自己个性化控制，可以利用这个方法,使用方法见官方说明
                }, 'onSelect': function (file) {//选择上传文件后调用
                    //success_callback.call(self, file, 'dfddd');
                }, 'onSelectError': function (file, errorCode, errorMsg) {
                    //返回一个错误，选择文件的时候触发
                    switch (errorCode) {
                        case -100:
                            alert("上传的文件数量已经超出系统限制的" + $(element).uploadify('settings', 'queueSizeLimit') + "个文件！");
                            break;
                        case -110:
                            alert("文件 [" + file.name + "] 大小超出系统限制的" + $(element).uploadify('settings', 'fileSizeLimit') + "大小！");
                            break;
                        case -120:
                            alert("文件 [" + file.name + "] 大小异常！");
                            break;
                        case -130:
                            alert("文件 [" + file.name + "] 类型不正确！");
                            break;
                    }
                }, 'onFallback': function () {
                    $(".uploadify3").hide();
                    $(".juploder").show();
                    //alert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。");
                }, 'onUploadSuccess': function (file, responseData, response) {//上传到服务器，服务器返回相应信息到data里 response: true|false
                    try {
                        var datas = $.parseJSON(responseData);
                        success_callback.call(self, datas, file, responseData, response, element);
                    } catch (e) {
                        alert("数据异常[Upload]……\r\n[" + action + "]" + responseData);
                    }
                }
            });
        });
    });

}

Ucenter.beforeSubmitResponse = function () {
    var returnVal = true;
    $('[data-demand="required"]').each(function (index, element) {
        returnVal *= checkInputValue(element);
    });
    if (returnVal <= 0) {
        $('.page_loading').fadeOut();
    }
    return returnVal > 0 ? true : false;
}
Ucenter.submitResponseError = function (res) {
    switch (res.follow) {
        case 'mobile':
            Ucenter.inputSetError($('[name="CL-mobile"]'), res.message);
            break;
        case 'reg-smscode':
            Ucenter.inputSetError($('[name="CL-smscode"]'), res.message);
            break;
        case 'undefined':
            Ucenter.alert(res);
            break;
        default:
            if ($('[name="' + res.follow + '"]').length > 0) {
                Ucenter.inputSetError($('[name="' + res.follow + '"]'), res.message);
            } else {
                Ucenter.alert(res);
            }
            break;
    }
}
Ucenter.jsonToForm = function (formData, formEle) {
    for (var key in formData) {
        var ele = formEle.find('[name="' + key + '"]');
        var inputGroup = formData.inputGroup;
        if (typeof(inputGroup) != 'undefined') {
            if (inputGroup.length > 0 & $.inArray(key, inputGroup.split(',')) >= 0) {
                ele = formEle.find('[name="' + key + '[]"]');
            }
        }
        if (ele.size() > 0) {
            switch (ele.attr('type')) {
                case 'radio':
                    ele.parent().find('[value="' + formData[key] + '"]').attr('checked', 'checked');
                    break;
                case 'checkbox':
                    //ele.attr('checked', false);alert([key,formData[key] ]);
                    if (formData[key].indexOf(',') > 0) {
                        var vals = formData[key].split(',');
                        for (var i = 0; i < vals.length; i++) {
                            ele.parent().find('[value="' + vals[i] + '"]').attr('checked', 'checked');
                        }
                    } else {
                        ele.parent().find('[value="' + formData[key] + '"]').attr('checked', 'checked');
                    }
                    break;
                default:
                    ele.val(formData[key]);
                    break;
            }
        }
    }
}

/**
 * [creatModalFrame 创建模态框]
 * @param  {object} params 属性对象
 */
Ucenter.creatModalFrame = function (params) {
    <!-- Small modal -->
    $('.modal, .modal-backdrop').remove();
    var date = new Date();
    var modalId = typeof(params.modalId) == "undefined" || params.modalId == "undefined" ? "Modal-" + date.getTime() : params.modalId;
    var dialogClass = typeof(params.dialogClass) == "undefined" || params.dialogClass == "undefined" ? '' : params.dialogClass;
    var eleStr = '<div id="' + modalId + '" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">' +//.bs-example-modal-sm
        '<div class="modal-dialog ' + dialogClass + '">' +// modal-sm
        '<div class="modal-content">' +
        '<div class="modal-header">' +
        '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>' +
        '<h4 class="modal-title" id="myModalLabel">title</h4>' +
        '</div>' +
        '<div class="modal-body">content</div>' +
        '<div class="modal-footer">' +
        '<button type="button" class="btn btn-default" data-dismiss="modal">确 定</button>' +
        '</div>' +
        '</div>' +
        '</div></div>';
    var loadingStr = '<div class="modal-header hide">' +
        '<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>' +
        '<h4 class="modal-title"></h4>' +
        '</div>' +
        '<div class="modal-body"><p>&nbsp; </p>' +
        '<div class="progress">' +
        '<div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width:100%">' +
        '<span class="sr-only">45% Complete</span>' +
        '</div>' +
        '</div>' +
        '<p class="text-center">正在努力处理中，请稍候。。。</p>' +
        '</div>';
    $('body').append(eleStr);
    if (typeof(params.content) != "undefined" & params.content != "undefined") {
        $('#' + modalId).find('.modal-content').html(params.content);
    }
    if (typeof(params.loadingModal) != "undefined" & params.loadingModal == true) {
        $('#' + modalId).attr('data-backdrop', 'static');
        $('#' + modalId).find('.modal-content').html(loadingStr);
    }
    var option = {show: true, keyboard: false, backdrop: 'static'};
    if (typeof(params.dialogBackdrop) == "undefined") {
        //option.backdrop = true;
    } else {
        option.backdrop = params.dialogBackdrop;
    }
    $('#' + modalId).modal(option);
    //$('#'+modalId).modal('show');
    $('#' + modalId).on('hidden.bs.modal', function (e) {
        $('#' + modalId).remove();
    })
    $('#' + modalId).on('shown.bs.modal', function (e) {
        if ($('#' + modalId).find('[data-blind="ckeditor"]').size() > 0) {
            $('#' + modalId).find('[data-blind="ckeditor"]').each(function (index, element) {
                var toolbar = typeof($(this).attr("editor-toolbar")) == "undefined" ? "Basic" : $(this).attr("editor-toolbar");
                var height = typeof($(this).attr("editor-height")) == "undefined" ? 300 : $(this).attr("editor-height");
                CKEDITOR.replace($(this).attr("id"), {
                    toolbar: toolbar, height: height
                });
            });
        }
    })
    //检查是否需要加载图片上传组件
    if ($('#' + modalId + ' [data-modal="uploadify3"]').size() > 0) {
        if (typeof(uploaderResponseInPage) == 'function') uploaderResponseInPage();
    }
}

$(document).on('click', '[data-toggle="ajaxModal"]', function () {
    var href = $(this).attr('href'), dialogClass = $(this).attr('data-dailogClass'), modalId = $(this).attr('data-modalId');
    var dialogBackdrop = $(this).attr('data-backdrop');
    href = typeof(href) == "undefined" ? $(this).attr('data-href') : href;
    modalId = typeof(modalId) == "undefined" ? 'undefined' : modalId;
    dialogClass = typeof(dialogClass) == "undefined" ? '' : dialogClass;
    $.getJSON(href, function (res) {
        if ('undefined' == res || res.error > 0) {
            Ucenter.alert(res);
        } else {
            var option = {content: res.content, dialogClass: dialogClass, modalId: modalId};
            if (typeof(dialogBackdrop) != "undefined") {
                option.dialogBackdrop = dialogBackdrop;
            }
            Ucenter.creatModalFrame(option);
            $('[data-demand="required"]').on('blur', this, function (e) {
                checkInputValue($(this));
            })
            if (typeof(res.formData) != 'undefined' & typeof(res.formData) == 'object') {
                Ucenter.jsonToForm(res.formData, $('.modal form').last());
            }
        }
    });
    return false;
})
$(document).on('click', '.formButton', function () {
    $(this).parents('form').find('[data-name="formAct"]').val($(this).attr('data-formAct'));
    $(this).parents('form').submit();
})
$(document).on('submit', '[data-action="ajaxForm"], [data-action="ajaxPageForm"]', function () {
    $('.page_loading').show();
    $(this).ajaxSubmit({//target: '#output',          //把服务器返回的内容放入id为output的元素中
        beforeSubmit: function (formData, jqForm, options) {
            return Ucenter.beforeSubmitResponse();
        }, success: function (responseText, statusText) {
            $('.page_loading').fadeOut();
            try {
                var res = $.parseJSON(responseText);
                if ('undefined' == res || res.error > 0) {
                    Ucenter.submitResponseError(res);
                } else {
                    //document.location = res.redirect;
                    Ucenter.alert(res, function () {
                        if (!$("#holdModal").prop('checked')) {
                            $('[data-dismiss="modal"]').trigger('click');
                        }
                        if (res.followUp) {
                            Ucenter.ajaxFollowUp(res);
                        }
                    });
                    //$("#tableList").html(res.list_data);
                }
            } catch (e) {
                alert(statusText + ":数据异常……\r\n[" + responseText + "]");
            }
        },
        timeout: 20000
    });
    return false;
})

$(document).on('submit', '[data-action="listSearchForm"]', function () {
    pagerFilter.keywords = $(this).find('[name="keywords"]').val();
    $('[data-name="filterKey"]').each(function (index, element) {
        pagerFilter[$(this).attr('name')] = $(this).val();
    });
    Ucenter.loadPage(1);
    return false;
})

$(document).on('click', '[data-action="toggleStatus"], [data-action="listRemove"], [data-action="loadPager"]',
    function () {
        var dataAction = $(this).attr('data-action');//alert(dataAction);
        switch (dataAction) {
            case 'toggleStatus':
                Ucenter.toggleStatus(this);
                break;
            case 'listRemove':
                Ucenter.listRemove(this);
                break;
            case 'loadPager':
                var page = $(this).attr('data-page');
                page = typeof(page) == "undefined" ? 1 : page;
                if (page > 0) Ucenter.loadPage(page);
                break;
        }
        return false;
    });
$(document).on('click', '[data-dismiss="modalReFresh"]', function () {
    //pagerFilter.keywords = $(this).find('[name="keywords"]').val();
    $('[data-dismiss="modal"]').trigger('click');
    Ucenter.loadPage(1);
    return false;
})
Ucenter.ajaxFollowUp = function (res) {
    var action = res.followUp;
    switch (action) {
        case 'queryList':
            Ucenter.loadPage();
            break;
        case 'resetPageForm':
            $('[data-action="ajaxPageForm"] [type="reset"]').trigger('click');
            break;
        case 'orderFinishCounts':
            $("#orderFinishMoneyPay").val(res.order_amount);
            break;
        case 'redirect':
            document.location = res.redirect;
            break;
        default:
            Ucenter.alert(res);
            break;
    }
}
Ucenter.loadPage = function (page) {
    listTable.loadList();
    //Ucenter.listRemove 有使用 listTable.compileFilter
}
///////////////////////////////////////////////////////////////
Ucenter.listRemove = function (obj) {
    var target = $(this).attr('data-target');
    var href = $(obj).attr('data-href');
    if (typeof(href) == "undefined") {
        href = $(obj).attr('href');
    }
    if (typeof(href) == "undefined" || href.indexOf('javascript') >= 0 || href.indexOf('#') >= 0) {
        return false;
    }
    target = typeof(target) == "undefined" ? '#tableList' : target;
    if (typeof(pagerFilter) != "undefined") {
        href += listTable.compileFilter(pagerFilter);
    }

    var hasConfirm = $(obj).attr('data-confirm');
    if (typeof(hasConfirm) != "undefined") {
        if (confirm(hasConfirm)) {
            listRemoveSbu(href, target);
        }
    } else {
        listRemoveSbu(href, target);
    }
    return false;
}
function listRemoveSbu(href, target) {
    $.getJSON(href, function (res) {
        if ('undefined' == res || res.error > 0) {
            Ucenter.alert(res);
        } else {
            $(target).html(res.content);
            if (res.followUp) {
                Ucenter.ajaxFollowUp(res);
            }
        }
    });
}
Ucenter.toggleStatus = function (obj) {
    var href = $(obj).attr('href');
    href = typeof(href) == "undefined" ? $(obj).attr('data-href') : href;
    $.getJSON(href, function (res) {
        if ('undefined' == res || res.error > 0) {
            Ucenter.alert(res);
        } else {
            Ucenter.alert(res, function () {
                $(obj).parent().children().removeClass('hide');
                $(obj).addClass('hide');
                if (res.followUp) {
                    Ucenter.ajaxFollowUp(res);
                }
            });

        }
    });
    return false;
}
$('[data-action="get_datas"]').on('click', this, function (e) {
    var obj = this, target = $(this).attr('data-target'), href = $(this).attr('href'), hasConfirm = $(this).attr('data-confirm');
    href = typeof(href) == "undefined" ? $(this).attr('data-href') : href;
    if (typeof(target) == "undefined") {
        Ucenter.alert({message: '缺少参数！'});
        return false;
    }
    if (typeof(hasConfirm) != "undefined") {
        if (!confirm(hasConfirm)) return false;
    }
    $.getJSON(href, function (res) {
        if ('undefined' == res || res.error > 0) {
            Ucenter.alert(res);
            return false;
        } else {
            $(target).html(res.content);
        }
    });
    return false;
});
//============
$('[data-toggle="ajaxListRemove"]').on('click', this, function () {
    var href = $(this).attr('href');
    href = typeof(href) == "undefined" ? $(this).attr('data-href') : href;
    var hasConfirm = $(this).attr('data-confirm');
    if (typeof(hasConfirm) != "undefined") {
        if (confirm(hasConfirm)) {
            ajaxListRemoveSub(href);
        }
    } else {
        ajaxListRemoveSub(href);
    }

    return false;
})
function ajaxListRemoveSub(href) {
    $.getJSON(href, function (res) {
        if ('undefined' == res || res.error > 0) {
            Ucenter.alert(res);
        } else {
            $("#tableList").html(res.list_data);
        }
    });
}

$(document).on('click', '[data-toggle="ajaxPickValue"]', function () {
    var href = $(this).attr('data-href'), destInputName = $(this).attr('data-destInputName');
    $.getJSON(href, function (res) {
        if ('undefined' == res || res.error > 0) {
            Ucenter.alert(res);
        } else {
            $('[name="' + destInputName + '"]').val(res.content);
        }
    });
    return false;
})

function fomart_mobile(obj, selfShow) {
    var val = $(obj).val();
    var destInputName = $(obj).attr('name') + '_sample';
    var dest_val = val.substr(0, 3) + ' ' + val.substr(3, 4) + ' ' + val.substr(7);
    if (selfShow == 'sample') {
        $("#" + destInputName).html(dest_val);
    } else {
        $(obj).val(dest_val);
    }
}

